package com.ruoyi.web.controller.drugSystem.drugInfo;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.drugSystem.domain.SysStockCk;
import com.ruoyi.drugSystem.domain.SysStockInfo;
import com.ruoyi.drugSystem.domain.SysStockRk;
import com.ruoyi.drugSystem.service.ISysStockCkService;
import com.ruoyi.drugSystem.service.ISysStockInfoService;
import com.ruoyi.drugSystem.service.ISysStockRkService;
import com.ruoyi.framework.web.service.SysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/pdx/DrugNum")
public class DrugNumController extends BaseController {

    @Autowired
    private ISysStockRkService sysStockRkService;
    @Autowired
    private ISysStockCkService sysStockCkService;
    @Autowired
    private ISysStockInfoService sysStockInfoService;
    @Autowired
    private SysPermissionService permissionService;

    /**
     * 查询总阅读量/文章总数/评论总数/留言总数
     */
    @GetMapping("/total")
    public Map total() {
        Map total = new HashMap();
        List<SysStockInfo> sysStockInfos = sysStockInfoService.selectSysStockInfoList(new SysStockInfo());
        List<SysStockRk> sysStockRks = sysStockRkService.selectSysStockRkList(new SysStockRk());
        List<SysStockCk> sysStockCks = sysStockCkService.selectSysStockCkList(new SysStockCk());
        long sum = sysStockInfos.stream().mapToLong(SysStockInfo::getNumber).sum();
        long rkCount = sysStockRks.stream().mapToLong(SysStockRk::getNumber).sum();
        long ckCount = sysStockCks.stream().mapToLong(SysStockCk::getNumber).sum();
        System.out.println(ckCount);
        total.put("sum",sum);
        total.put("rkCount",rkCount);
        total.put("ckCount",ckCount);
        total.put("money",1000000l);
        return total;
    }


    /**
     * 返回某个日期前几天的开始日期
     */
    public static Date getFrontDayBegin(Date date, int i) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }

    /**
     * 返回某个日期前几天的结束日期
     */
    public static Date getFrontDayEnd(Date date, int i) {
        Calendar cal = new GregorianCalendar();
        cal.setTime(date);
        cal.set(Calendar.DATE, cal.get(Calendar.DATE) - i);
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        return cal.getTime();
    }
}
